package studychinese.activity;

import android.app.Dialog;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.jaeger.library.StatusBarUtil;

import studychinese.model.CustomDialog;


public class SettingActivity extends BaseAcitivity implements View.OnClickListener {
    private RelativeLayout  langue_my;
    private RelativeLayout  mine_my;
    private RelativeLayout  message_my;
    private RelativeLayout  back_my;
    private ImageView backSetting;
    private AlertDialog dialog;
    private TextView setLangue;
    private LinearLayout ll_back;

    @Override
    protected int setContainer() {
        return R.layout.activity_setting;
    }

    @Override
    public void innitView()
    {

        langue_my = (RelativeLayout) findViewById(R.id.rl_setting_langue);
        mine_my = (RelativeLayout) findViewById(R.id.rl_setting_mine);
        message_my = (RelativeLayout) findViewById(R.id.rl_setting_message);
        back_my = (RelativeLayout) findViewById(R.id.rl_setting_back);
        ll_back = (LinearLayout) findViewById(R.id.ll_back);
        backSetting = (ImageView) findViewById(R.id.iv_setting_back);
        setLangue = (TextView) findViewById(R.id.tv_setting_setLangue);
        backSetting.setOnClickListener(this);
        langue_my.setOnClickListener(this);
        mine_my.setOnClickListener(this);
        message_my.setOnClickListener(this);
        back_my.setOnClickListener(this);
    }
    @Override
    protected void setStatusBar() {
        StatusBarUtil.setTranslucentForImageView(this, 0, ll_back);
    }
    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            /**
             *   仿ios的一个选择器
             */

            case R.id.rl_setting_langue:
                final Dialog bottomDialog = new Dialog(this, R.style.BottomDialog);
                View contentView = LayoutInflater.from(this).inflate(R.layout.setting_pop_layout, null);
                TextView  sethan= (TextView) contentView.findViewById(R.id.tv_dialog_sethan_paizhao);
                TextView  setEnglish = (TextView) contentView.findViewById(R.id.tv_dialog_setEnglish_paizhao);
                TextView setHan = (TextView) contentView.findViewById(R.id.tv_dialog_setHan_xiangce);
                TextView no = (TextView) contentView.findViewById(R.id.tv_no_cancle);
                sethan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setLangue.setText("简体中文");
                        bottomDialog.dismiss();
                    }
                });
                setEnglish.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setLangue.setText("English");
                        bottomDialog.dismiss();
                    }
                });
                setHan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setLangue.setText("한국어읽기");
                        bottomDialog.dismiss();
                    }
                });
                no.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        bottomDialog.dismiss();
                    }
                });
                bottomDialog.setContentView(contentView);
                ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
                layoutParams.width = getResources().getDisplayMetrics().widthPixels;
                contentView.setLayoutParams(layoutParams);
                bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
                bottomDialog.setCanceledOnTouchOutside(true);
                bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
                bottomDialog.show();
                break;
            case R.id.rl_setting_mine:
                startActivity(new Intent(SettingActivity.this, AboutUsActivity.class));
                break;
            case R.id.rl_setting_message:
                startActivity(new Intent(SettingActivity.this, MessageActivity.class));
                break;
            case R.id.rl_setting_back:
                final CustomDialog dialog=new CustomDialog(this, R.style.mystyle, R.layout.back_dialog_layout);
                dialog.show();
                break;
            case R.id.iv_setting_back:
                finish();
                break;
        }
    }
}
